﻿using System;
using System.Data;
using System.Text;
using OrderManage.Utility;

namespace OrderManage.DAL
{
    public class CommonDAL : DbHelperBase
    {
        public int CheckedCode(string tableName, string fieldName, string code)
        {
            var strSql = new StringBuilder();
            strSql.Append(string.Format(" select  count(*) AS total FROM [{0}] Where [{1}] = '{2}' ", tableName, fieldName, code));
            var count = 0;
            using (var cmd = Db.GetSqlStringCommond(strSql.ToString()))
            {
                try
                {
                    using (IDataReader reader = Db.ExecuteReader(cmd))
                    {
                        if (reader.Read())
                        {
                            count = Convert.ToInt32(reader["total"]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EventsLog.WriteLog("ErrorInfo" + ex.Message);
                }
                return count;
            }
        }
    }
}
